﻿Imports System.Xml
''' <summary>
''' 数据项目
''' </summary>
''' <remarks></remarks>
Public MustInherit Class clsDataObject
    ''' <summary>
    ''' 数据名称
    ''' </summary>
    ''' <remarks></remarks>
    Public Name As String
    ''' <summary>
    ''' 获得转换为COBOL时候的PIC描述
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public MustOverride Function GetPicDescrption() As System.Collections.Generic.List(Of String)
    ''' <summary>
    ''' 获得实际内存中的占用长度
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public MustOverride Function GetUsage() As Integer
    ''' <summary>
    ''' 填写XML属性节点
    ''' </summary>
    ''' <param name="mNode"></param>
    ''' <param name="strWords"></param>
    ''' <remarks></remarks>
    Public MustOverride Sub SetXmlAttributeByWordList(ByVal mNode As XmlElement, ByVal strWords As List(Of String))
    ''' <summary>
    ''' 获得大机占用内存长度（16Bit数据占用1个长度单位，半个FULLWORD）
    ''' </summary>
    ''' <param name="mDataNode"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Shared Function GetUsageByXmlElement(ByVal mDataNode As XmlElement) As Integer
        Dim T As clsDataObject = GetDataObject(mDataNode)
        If T Is Nothing Then
            Return 0
        Else
            Return T.GetUsage()
        End If
    End Function
    Public Shared Function GetPicDescrptionByXmlElement(ByVal mDataNode As XmlElement) As System.Collections.Generic.List(Of String)
        Dim T As clsDataObject = GetDataObject(mDataNode)
        If T Is Nothing Then
            Return Nothing
        Else
            Return T.GetPicDescrption()
        End If
    End Function
    ''' <summary>
    ''' 设定数据类型
    ''' </summary>
    ''' <param name="mNode"></param>
    ''' <param name="strWords"></param>
    ''' <remarks></remarks>
    Public Shared Function SetDataType(ByRef mNode As XmlElement, ByVal strWords As List(Of String)) As XmlElement
        mNode.SetAttribute("INIT", GetAttr("INIT", strWords))
        '带有BASED属性
        If HasTokenStartWith("BASED(", strWords) Then
            mNode.SetAttribute("BASED", GetAttr("BASED", strWords))
        End If
        '静态变量
        If HasTOKEN("STATIC", strWords) Then
            mNode.SetAttribute("STATIC", True)
        End If
        '变长变量
        If HasTOKEN("VAR", strWords) Then
            mNode.SetAttribute("VAR", True)
        End If
        Dim rtnObj As clsDataObject = Nothing
        Select Case True
            Case HasTokenStartWith("BIT(", strWords)
                'BIT
                Dim rtnBitObj As BIT_DataItem = New BIT_DataItem
                rtnObj = rtnBitObj
            Case HasTokenStartWith("CHAR(", strWords)
                '字符，没有初值
                Dim rtnCharObj As CHAR_DataItem = New CHAR_DataItem
                rtnObj = rtnCharObj
            Case HasTokenStartWith("FIXED(", strWords)
                If HasTOKEN("BIN", strWords) Then
                    'FIXED BIN 
                    Dim rtnFixedObj As FIXED_BIN_DataItem = New FIXED_BIN_DataItem
                    rtnObj = rtnFixedObj
                Else
                    'FIXED DEC 
                    Dim rtnFixedObj As FIXED_DEC_DataItem = New FIXED_DEC_DataItem
                    rtnObj = rtnFixedObj
                End If
            Case HasTokenStartWith("BIN(", strWords) And HasTOKEN("FIXED", strWords)
                'FIXED BIN 
                Dim rtnFixedObj As FIXED_BIN_DataItem = New FIXED_BIN_DataItem
                rtnObj = rtnFixedObj
            Case HasTokenStartWith("DEC(", strWords) And HasTOKEN("FIXED", strWords)
                'FIXED DEC 
                Dim rtnFixedObj As FIXED_DEC_DataItem = New FIXED_DEC_DataItem
                rtnObj = rtnFixedObj
            Case HasTokenStartWith("G(", strWords)
                'G
                Dim rtnGObj As G_DataItem = New G_DataItem
                rtnObj = rtnGObj
            Case HasTokenStartWith("PIC'", strWords)
                'PIC
                Dim rtnPICObj As PIC_DataItem = New PIC_DataItem
                rtnObj = rtnPICObj
            Case HasTOKEN("PTR", strWords)
                '指针
                Dim rtnPointObj As POINT_DataItem = New POINT_DataItem
                rtnObj = rtnPointObj
        End Select
        If Not rtnObj Is Nothing Then
            rtnObj.SetXmlAttributeByWordList(mNode, strWords)
            Select Case rtnObj.GetType.FullName
                Case GetType(PIC_DataItem).FullName
                    mNode = PIC_DataItem.JustifyPIC(mNode)
                Case GetType(CHAR_DataItem).FullName
                    mNode = CHAR_DataItem.JustifyVarChar(mNode)
            End Select
        End If

        If HasTOKEN("DEF", strWords) Then
            mNode.SetAttribute("DEF", strWords(GetTokenPos("DEF", strWords)).Replace(";", String.Empty))
            If HasTokenStartWith("POS", strWords) Then
                mNode.SetAttribute("POS", GetAttr("POS", strWords))
            Else
                mNode.SetAttribute("POS", "1")
            End If
        End If
        Return mNode
    End Function
    ''' <summary>
    ''' 根据XML节点获得数据对象实例
    ''' </summary>
    ''' <param name="mDataNode"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private Shared Function GetDataObject(ByVal mDataNode As XmlElement) As clsDataObject
        Dim rtnObj As clsDataObject = Nothing
        Select Case mDataNode.GetAttribute("TYPE")
            Case "BIT"
                Dim rtnBitObj As BIT_DataItem = New BIT_DataItem
                rtnBitObj.BitLength = mDataNode.GetAttribute("LENGTH")
                rtnObj = rtnBitObj
            Case "CHAR"
                Dim rtnCharObj As CHAR_DataItem = New CHAR_DataItem
                rtnCharObj.Length = mDataNode.GetAttribute("LENGTH")
                rtnObj = rtnCharObj
            Case "FIXED DEC"
                Dim rtnFixedObj As FIXED_DEC_DataItem = New FIXED_DEC_DataItem
                rtnFixedObj.Digits = mDataNode.GetAttribute("LENGTH").Split(",")(0)
                If mDataNode.GetAttribute("LENGTH").Split(",").Length = 2 Then
                    rtnFixedObj.Factor = mDataNode.GetAttribute("LENGTH").Split(",")(1)
                End If
                If mDataNode.GetAttribute("SIGNED") = "FALSE" Then
                    rtnFixedObj.Signed = False
                Else
                    rtnFixedObj.Signed = True
                End If
                rtnObj = rtnFixedObj
            Case "FIXED BIN"
                Dim rtnFixedObj As FIXED_BIN_DataItem = New FIXED_BIN_DataItem
                rtnFixedObj.Digits = mDataNode.GetAttribute("LENGTH").Split(",")(0)
                If mDataNode.GetAttribute("LENGTH").Split(",").Length = 2 Then
                    rtnFixedObj.Factor = mDataNode.GetAttribute("LENGTH").Split(",")(1)
                End If
                If mDataNode.GetAttribute("SIGNED") = "FALSE" Then
                    rtnFixedObj.Signed = False
                Else
                    rtnFixedObj.Signed = True
                End If
                rtnObj = rtnFixedObj
            Case "G"
                Dim rtnGObj As G_DataItem = New G_DataItem
                rtnGObj.Length = mDataNode.GetAttribute("LENGTH")
                rtnObj = rtnGObj
            Case "PIC"
                Dim rtnCharObj As PIC_DataItem = New PIC_DataItem
                rtnCharObj.PICFormat = mDataNode.GetAttribute("PIC")
                rtnObj = rtnCharObj
            Case "PTR"
                Dim rtnPointObj As POINT_DataItem = New POINT_DataItem
                rtnObj = rtnPointObj
        End Select
        If rtnObj Is Nothing Then Return Nothing
        rtnObj.Name = mDataNode.GetAttribute("NAME")
        Return rtnObj
    End Function
End Class
''' <summary>
''' BIT数据类
''' </summary>
''' <remarks></remarks>
Public Class BIT_DataItem
    Inherits clsDataObject
    ''' <summary>
    ''' 长度
    ''' </summary>
    ''' <remarks></remarks>
    Public BitLength As Integer
    ''' <summary>
    ''' 占用长度
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Overrides Function GetUsage() As Integer
        Return BitLength / 8
    End Function
    ''' <summary>
    ''' 获取PIC描述
    ''' </summary>
    ''' <remarks></remarks>
    Public Overrides Function GetPicDescrption() As System.Collections.Generic.List(Of String)
        Dim strRtn As New List(Of String)
        Select Case BitLength
            Case 1
                strRtn.Add("PIC X(01)")
            Case 8
                strRtn.Add("PIC X(01)")
            Case Else
                strRtn.Add("*ERROR: BIT Length Is Not 1*")
                strRtn.Add("TYPE:BIT LENGTH:" & BitLength)
                LogWriter.WriteLine("*ERROR: BIT Length Is Not 1*")
                LogWriter.WriteLine("NAME  :" & Name)
                LogWriter.WriteLine("TYPE  :BIT")
                LogWriter.WriteLine("LENGTH:" & BitLength)
        End Select
        Return strRtn
    End Function
    ''' <summary>
    ''' 获取属性
    ''' </summary>
    ''' <param name="mNode"></param>
    ''' <param name="strWords"></param>
    ''' <remarks></remarks>
    Public Overrides Sub SetXmlAttributeByWordList(ByVal mNode As System.Xml.XmlElement, ByVal strWords As System.Collections.Generic.List(Of String))
        mNode.SetAttribute("TYPE", "BIT")
        mNode.SetAttribute("LENGTH", GetAttr("BIT", strWords))
    End Sub
End Class
''' <summary>
''' 字符型数据类
''' </summary>
''' <remarks></remarks>
Public Class CHAR_DataItem
    Inherits clsDataObject
    ''' <summary>
    ''' 字符长度
    ''' </summary>
    ''' <remarks></remarks>
    Public Length As Integer
    ''' <summary>
    ''' 占用长度
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Overrides Function GetUsage() As Integer
        Return Length
    End Function
    ''' <summary>
    ''' 获取PIC描述
    ''' </summary>
    ''' <remarks></remarks>
    Public Overrides Function GetPicDescrption() As System.Collections.Generic.List(Of String)
        Dim strRtn As New List(Of String)
        Dim strLength As String
        If Length < 10 Then
            strLength = Format(Length, "0#")
        Else
            strLength = Length.ToString
        End If
        strRtn.Add("PIC X(" & strLength & ")")
        Return strRtn
    End Function
    ''' <summary>
    ''' 获取属性
    ''' </summary>
    ''' <param name="mNode"></param>
    ''' <param name="strWords"></param>
    ''' <remarks></remarks>
    Public Overrides Sub SetXmlAttributeByWordList(ByVal mNode As System.Xml.XmlElement, ByVal strWords As System.Collections.Generic.List(Of String))
        mNode.SetAttribute("TYPE", "CHAR")
        mNode.SetAttribute("LENGTH", GetAttr("CHAR", strWords))
    End Sub
    Public Shared Function JustifyVarChar(ByVal mNode As XmlElement) As XmlElement
        '将变长变量转换为长度和内容的结构
        If mNode.GetAttribute("VAR") = "True" Then
            Dim NewNode As XmlElement = mXmlDocument.CreateElement("TREEDATA")
            NewNode.SetAttribute("NAME", mNode.GetAttribute("NAME"))
            NewNode.SetAttribute("LayNo", mNode.GetAttribute("LayNo"))
            Dim LengthNode As XmlElement = mXmlDocument.CreateElement("SINGLEDATA")
            LengthNode.SetAttribute("NAME", mNode.GetAttribute("NAME") & "_LEN")
            LengthNode.SetAttribute("LayNo", mNode.GetAttribute("LayNo") + 2)
            LengthNode.SetAttribute("TYPE", "FIXED BIN")
            LengthNode.SetAttribute("LENGTH", 15)
            NewNode.AppendChild(LengthNode)
            Dim TEXTNode As XmlElement = mXmlDocument.CreateElement("SINGLEDATA")
            TEXTNode.SetAttribute("NAME", mNode.GetAttribute("NAME") & "_TEXT")
            TEXTNode.SetAttribute("LayNo", mNode.GetAttribute("LayNo") + 2)
            TEXTNode.SetAttribute("TYPE", "CHAR")
            TEXTNode.SetAttribute("LENGTH", mNode.GetAttribute("LENGTH"))
            NewNode.AppendChild(TEXTNode)
            Return NewNode
        End If
        Return mNode
    End Function
End Class
''' <summary>
''' FIXED DEC数据类
''' </summary>
''' <remarks></remarks>
Public Class FIXED_DEC_DataItem
    Inherits clsDataObject
    ''' <summary>
    ''' 总位数
    ''' </summary>
    ''' <remarks></remarks>
    Public Digits As Integer
    ''' <summary>
    ''' 小数
    ''' </summary>
    ''' <remarks></remarks>
    Public Factor As Integer
    ''' <summary>
    ''' 符号
    ''' </summary>
    ''' <remarks></remarks>
    Public Signed As Boolean
    ''' <summary>
    ''' 占用长度
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Overrides Function GetUsage() As Integer
        '+12345在内存中的存放方法(COMP-3) C:正数 D:负数  F:绝对值
        '135
        '24C
        Return (Digits + 1) / 2
    End Function
    ''' <summary>
    ''' 获取PIC描述
    ''' </summary>
    ''' <remarks></remarks>
    Public Overrides Function GetPicDescrption() As System.Collections.Generic.List(Of String)
        Dim strRtn As New List(Of String)
        Dim strLength As String
        If Digits - Factor < 10 Then
            strLength = Format(Digits - Factor, "0#")
        Else
            strLength = Digits - Factor
        End If
        If Signed Then
            strLength = "PIC S9(" & strLength & ")"
        Else
            strLength = "PIC  9(" & strLength & ")"
        End If
        If Factor <> 0 Then
            If Factor < 10 Then
                strLength &= "V9(" & Format(Factor, "0#") & ")"
            Else
                strLength &= "V9(" & Factor & ")"
            End If
        End If
        strLength &= "  COMP-3"
        strRtn.Add(strLength)
        Return strRtn
    End Function
    ''' <summary>
    ''' 获取属性
    ''' </summary>
    ''' <param name="mNode"></param>
    ''' <param name="strWords"></param>
    ''' <remarks></remarks>
    Public Overrides Sub SetXmlAttributeByWordList(ByVal mNode As System.Xml.XmlElement, ByVal strWords As System.Collections.Generic.List(Of String))
        mNode.SetAttribute("TYPE", "FIXED DEC")
        If HasTokenStartWith("DEC(", strWords) Then
            mNode.SetAttribute("LENGTH", GetAttr("DEC", strWords))
        Else
            mNode.SetAttribute("LENGTH", GetAttr("FIXED", strWords))
        End If
    End Sub
End Class
''' <summary>
''' FIXED BIN数据类
''' </summary>
''' <remarks></remarks>
Public Class FIXED_BIN_DataItem
    Inherits clsDataObject
    ''' <summary>
    ''' 总位数
    ''' </summary>
    ''' <remarks></remarks>
    Public Digits As Integer
    ''' <summary>
    ''' 小数
    ''' </summary>
    ''' <remarks></remarks>
    Public Factor As Integer
    ''' <summary>
    ''' 符号
    ''' </summary>
    ''' <remarks></remarks>
    Public Signed As Boolean
    ''' <summary>
    ''' 占用长度
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Overrides Function GetUsage() As Integer
        '0111_0000_1111_0000在内存中的存放方法(COMP)
        '7F
        '00
        Return (Digits + 1) / 8
    End Function
    ''' <summary>
    ''' 获取PIC描述
    ''' </summary>
    ''' <remarks></remarks>
    Public Overrides Function GetPicDescrption() As System.Collections.Generic.List(Of String)
        Dim strRtn As New List(Of String)
        Select Case Digits
            Case 15
                If Signed Then
                    strRtn.Add("PIC S9(4)")
                Else
                    strRtn.Add("PIC 9(4)")
                End If
                strRtn.Add("COMP")
            Case 31
                If Signed Then
                    strRtn.Add("PIC S9(8)")
                Else
                    strRtn.Add("PIC 9(8)")
                End If
                strRtn.Add("COMP")
            Case Else
                strRtn.Add("*ERROR: FIXED BIN Length Is Not 15 Or 31*")
                strRtn.Add("TYPE:FIXED BIN LENGTH:" & Digits)
                LogWriter.WriteLine("*ERROR: FIXED BIN Length Is Not 15 Or 31*")
                LogWriter.WriteLine("NAME  :" & Name)
                LogWriter.WriteLine("TYPE  :FIXED BIN")
                LogWriter.WriteLine("LENGTH:" & Digits)
        End Select
        Return strRtn
    End Function
    ''' <summary>
    ''' 获取属性
    ''' </summary>
    ''' <param name="mNode"></param>
    ''' <param name="strWords"></param>
    ''' <remarks></remarks>
    Public Overrides Sub SetXmlAttributeByWordList(ByVal mNode As System.Xml.XmlElement, ByVal strWords As System.Collections.Generic.List(Of String))
        mNode.SetAttribute("TYPE", "FIXED BIN")
        mNode.SetAttribute("LENGTH", GetAttr("BIN", strWords))
    End Sub
End Class
''' <summary>
''' G数据类
''' </summary>
''' <remarks></remarks>
Public Class G_DataItem
    Inherits clsDataObject
    ''' <summary>
    ''' 文字数
    ''' </summary>
    ''' <remarks></remarks>
    Public Length As Integer
    ''' <summary>
    ''' 占用长度
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Overrides Function GetUsage() As Integer
        Return Length * 2
    End Function
    ''' <summary>
    ''' 获取PIC描述
    ''' </summary>
    ''' <remarks></remarks>
    Public Overrides Function GetPicDescrption() As System.Collections.Generic.List(Of String)
        Dim strRtn As New List(Of String)
        Dim strLength As String
        If Length < 10 Then
            strLength = Format(Length, "0#")
        Else
            strLength = Length.ToString
        End If
        strRtn.Add("PIC G(" & strLength & ")")
        strRtn.Add("USAGE  DISPLAY-1")
        Return strRtn
    End Function
    ''' <summary>
    ''' 获取属性
    ''' </summary>
    ''' <param name="mNode"></param>
    ''' <param name="strWords"></param>
    ''' <remarks></remarks>
    Public Overrides Sub SetXmlAttributeByWordList(ByVal mNode As System.Xml.XmlElement, ByVal strWords As System.Collections.Generic.List(Of String))
        mNode.SetAttribute("TYPE", "G")
        mNode.SetAttribute("LENGTH", GetAttr("G", strWords))
    End Sub
End Class
''' <summary>
''' POINT数据类
''' </summary>
''' <remarks></remarks>
Public Class POINT_DataItem
    Inherits clsDataObject
    ''' <summary>
    ''' 占用长度
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Overrides Function GetUsage() As Integer
        Return 4
    End Function
    ''' <summary>
    ''' 获取PIC描述
    ''' </summary>
    ''' <remarks></remarks>
    Public Overrides Function GetPicDescrption() As System.Collections.Generic.List(Of String)
        Dim strRtn As New List(Of String)
        strRtn.Add("USAGE IS POINTER")
        Return strRtn
    End Function
    ''' <summary>
    ''' 获取属性
    ''' </summary>
    ''' <param name="mNode"></param>
    ''' <param name="strWords"></param>
    ''' <remarks></remarks>
    Public Overrides Sub SetXmlAttributeByWordList(ByVal mNode As System.Xml.XmlElement, ByVal strWords As System.Collections.Generic.List(Of String))
        mNode.SetAttribute("TYPE", "PTR")
    End Sub
End Class
''' <summary>
''' PIC数据类
''' </summary>
''' <remarks></remarks>
Public Class PIC_DataItem
    Inherits clsDataObject
    Public PICFormat As String
    ''' <summary>
    ''' 占用长度
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Overrides Function GetUsage() As Integer
        If PICFormat.StartsWith("(") And PICFormat.EndsWith(")9") Then
            Return Mid(PICFormat, 2, PICFormat.Length - 3)
        Else
            Return PICFormat.Length
        End If
    End Function
    ''' <summary>
    ''' 获取属性
    ''' </summary>
    ''' <param name="mNode"></param>
    ''' <param name="strWords"></param>
    ''' <remarks></remarks>
    Public Overrides Sub SetXmlAttributeByWordList(ByVal mNode As System.Xml.XmlElement, ByVal strWords As System.Collections.Generic.List(Of String))
        mNode.SetAttribute("TYPE", "PIC")
        mNode.SetAttribute("PIC", GetAttr("PIC", strWords))
    End Sub
    ''' <summary>
    ''' 获取PIC描述
    ''' </summary>
    ''' <remarks></remarks>
    Public Overrides Function GetPicDescrption() As System.Collections.Generic.List(Of String)
        Dim strRtn As New List(Of String)
        Dim strPic As String = PICFormat
        '根据项目经验和客户QA的决定，将Y改为9
        strPic = strPic.Replace("Y", "9")
        If strPic.StartsWith("(") Then
            'PL1"(A)B"  COBOL B(A) 
            Dim strPicLength As String = Mid(strPic, InStr(strPic, "(") + 1, InStr(strPic, ")") - InStr(strPic, "(") - 1)
            If IsNumeric(strPicLength) Then
                If CInt(strPicLength) < 10 Then
                    strPicLength = Format(CInt(strPicLength), "0#")
                End If
            End If
            strPic = Mid(strPic, InStr(strPic, ")") + 1) & "(" & strPicLength & ")"
        End If
        strPic = "PIC " & strPic
        strRtn.Add(strPic)
        Return strRtn
    End Function
    Public Shared Function JustifyPIC(ByVal mNode As XmlElement) As XmlElement
        'PIC调整结构 Ref:式样书：数据部-整理:PIC
        ''带有 “/” 的PIC 的调整,不过"/"貌似无需调整
        If mNode.GetAttribute("PIC").Split("/").Length > 1 Then
            mNode = PIC_DataItem.JustifyMethod(mNode, "/")
        End If
        If mNode.GetAttribute("PIC").Split(".").Length > 1 Then
            mNode = PIC_DataItem.JustifyMethod(mNode, ".")
        End If
        Return mNode
    End Function
    ''' <summary>
    ''' 调整PIC类型
    ''' </summary>
    ''' <param name="SingleDataXml"></param>
    ''' <remarks></remarks>
    Private Shared Function JustifyMethod(ByVal SingleDataXml As XmlElement, ByVal ReplMark As Char) As XmlNode
        Dim PicTreeNode As XmlElement = mXmlDocument.CreateElement("TREEDATA")
        PicTreeNode.SetAttribute("NAME", SingleDataXml.GetAttribute("NAME"))
        PicTreeNode.SetAttribute("REPEAT", SingleDataXml.GetAttribute("REPEAT"))
        PicTreeNode.SetAttribute("COMMENT", SingleDataXml.GetAttribute("COMMENT"))
        PicTreeNode.SetAttribute("LayNo", SingleDataXml.GetAttribute("LayNo"))
        Dim PicArray As String() = SingleDataXml.GetAttribute("PIC").Split(ReplMark)
        For picCount As Byte = 0 To PicArray.Length - 1
            Dim smallPic As XmlElement = mXmlDocument.CreateElement("SINGLEDATA")
            smallPic.SetAttribute("NAME", SingleDataXml.GetAttribute("NAME") & "-" & (picCount + 1).ToString)
            smallPic.SetAttribute("TYPE", "PIC")
            smallPic.SetAttribute("LayNo", SingleDataXml.GetAttribute("LayNo") + 2)
            smallPic.SetAttribute("PIC", PicArray(picCount))
            smallPic.SetAttribute("REPEAT", "1")
            PicTreeNode.AppendChild(smallPic)
            If picCount <> PicArray.Length - 1 Then
                Dim smallPic2 As XmlElement = mXmlDocument.CreateElement("SINGLEDATA")
                smallPic2.SetAttribute("NAME", "FILLER")
                smallPic2.SetAttribute("TYPE", "CHAR")
                smallPic2.SetAttribute("LENGTH", "1")
                smallPic2.SetAttribute("LayNo", SingleDataXml.GetAttribute("LayNo") + 2)
                smallPic2.SetAttribute("INIT", "'" & ReplMark & "'")
                smallPic2.SetAttribute("REPEAT", "1")
                PicTreeNode.AppendChild(smallPic2)
            End If
        Next
        Return PicTreeNode
        LogWriter.WriteLine("*WARNING: Change PIC 'Y' Format To TreeData")
        LogWriter.WriteLine("NAME:" & SingleDataXml.GetAttribute("NAME"))
        LogWriter.WriteLine("PIC :" & SingleDataXml.GetAttribute("PIC"))
    End Function
End Class

